using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using Slaks.DocumentSerialization.Document;
using Slaks.Graphs;

namespace Slaks.Analysis.Forms
{
	/// <summary>
	/// Summary description for GraphView.
	/// </summary>
	public class GraphSingleView : Form
	{
		private TabControl m_tabControl;
		private Container components = null;

		private Graph m_graph;
		private Document m_document;
		private RichTextBox m_informationRTB;
		private TabPage m_documentTP;
		private TabPage m_graphTP;
		private RichTextBox m_graphRTB;
		private RichTextBox m_documentRTB;
		private TabPage m_informationTP;
		private InformationADT m_informationAdt;

		public GraphSingleView(Document document, Graph graph, InformationADT information)
		{
			InitializeComponent();
			m_graph = graph;
			m_document = document;
			m_informationAdt = information;
			ShowInformation();
			ShowDocument();
			ShowGraph();
			this.Show();
		}

		private void ShowInformation()
		{
			StringBuilder builder = new StringBuilder();
			builder.Append("Representation : " + m_informationAdt.Representation + Environment.NewLine);
			builder.Append("DistanceValue : " + m_informationAdt.DistanceValue + Environment.NewLine);
			builder.Append("DistanceAlgorithm : " + m_informationAdt.DistanceAlgorithm + Environment.NewLine);
			builder.Append("Graph size : " + m_informationAdt.TypeSize + Environment.NewLine);
			builder.Append("File : " + m_document.FileName + Environment.NewLine);
			builder.Append("Total terms : " + m_document.UniqueTermCount + Environment.NewLine);
			m_informationRTB.Text += builder.ToString();
		}

		private void ShowDocument()
		{
			StringBuilder builder = new StringBuilder();

			foreach (Node node in m_document.Nodes)
			{
				builder.Append(node.Id + " " + node.Term + Environment.NewLine);

				foreach (Section section in node.Sections)
				{
					builder.Append("	Section : " + section.GetSectionTypeString() + Environment.NewLine);

					foreach (Sentence sentence in section.Sentences)
					{
						long nextId = sentence.NextId;
						if (nextId < 0) continue;
						string term = m_document.GetNodeById(nextId).Term;
						builder.Append("		Next-id : " + nextId + " , " + term + Environment.NewLine);
					}
				}
			}

			m_documentRTB.Text = builder.ToString();
		}

		private void ShowGraph()
		{
			StringBuilder builder = new StringBuilder();

			builder.Append("Graph name : " + m_graph.Name + Environment.NewLine + Environment.NewLine);
			foreach (Vertex vertex in m_graph.GetVertexList())
			{
				builder.Append("Id : " + vertex.GetId() + ", " + m_document.GetNodeById(vertex.GetId()).Term + " , Frequency : " + vertex.Frequency + Environment.NewLine);
				SectionType2EdgeListMap sectionType2EdgeListMap = vertex.GetSection2EdgeMap();
				foreach (string sectionType in sectionType2EdgeListMap.Keys)
				{
					builder.Append("	SectionType : " + sectionType + Environment.NewLine);
					EdgeList edgeList = sectionType2EdgeListMap[sectionType];
					foreach (Edge edge in edgeList)
					{
						builder.Append("		Target : " + edge.GetTarget().GetId() + " , Edge Frequency : " + edge.GetFrequency() + Environment.NewLine);
					}
				}
			}

			m_graphRTB.Text = builder.ToString();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.m_tabControl = new System.Windows.Forms.TabControl();
			this.m_documentTP = new System.Windows.Forms.TabPage();
			this.m_documentRTB = new System.Windows.Forms.RichTextBox();
			this.m_graphTP = new System.Windows.Forms.TabPage();
			this.m_informationTP = new System.Windows.Forms.TabPage();
			this.m_informationRTB = new System.Windows.Forms.RichTextBox();
			this.m_graphRTB = new System.Windows.Forms.RichTextBox();
			this.m_tabControl.SuspendLayout();
			this.m_documentTP.SuspendLayout();
			this.m_graphTP.SuspendLayout();
			this.m_informationTP.SuspendLayout();
			this.SuspendLayout();
			// 
			// m_tabControl
			// 
			this.m_tabControl.Controls.Add(this.m_informationTP);
			this.m_tabControl.Controls.Add(this.m_documentTP);
			this.m_tabControl.Controls.Add(this.m_graphTP);
			this.m_tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_tabControl.Location = new System.Drawing.Point(0, 0);
			this.m_tabControl.Name = "m_tabControl";
			this.m_tabControl.SelectedIndex = 0;
			this.m_tabControl.Size = new System.Drawing.Size(736, 526);
			this.m_tabControl.TabIndex = 0;
			// 
			// m_documentTP
			// 
			this.m_documentTP.Controls.Add(this.m_documentRTB);
			this.m_documentTP.Location = new System.Drawing.Point(4, 22);
			this.m_documentTP.Name = "m_documentTP";
			this.m_documentTP.Size = new System.Drawing.Size(728, 500);
			this.m_documentTP.TabIndex = 0;
			this.m_documentTP.Text = "Document";
			// 
			// m_documentRTB
			// 
			this.m_documentRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_documentRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_documentRTB.Location = new System.Drawing.Point(0, 0);
			this.m_documentRTB.Name = "m_documentRTB";
			this.m_documentRTB.ReadOnly = true;
			this.m_documentRTB.Size = new System.Drawing.Size(728, 500);
			this.m_documentRTB.TabIndex = 0;
			this.m_documentRTB.Text = "";
			// 
			// m_graphTP
			// 
			this.m_graphTP.Controls.Add(this.m_graphRTB);
			this.m_graphTP.Location = new System.Drawing.Point(4, 22);
			this.m_graphTP.Name = "m_graphTP";
			this.m_graphTP.Size = new System.Drawing.Size(728, 500);
			this.m_graphTP.TabIndex = 1;
			this.m_graphTP.Text = "Graph";
			// 
			// m_informationTP
			// 
			this.m_informationTP.Controls.Add(this.m_informationRTB);
			this.m_informationTP.Location = new System.Drawing.Point(4, 22);
			this.m_informationTP.Name = "m_informationTP";
			this.m_informationTP.Size = new System.Drawing.Size(728, 500);
			this.m_informationTP.TabIndex = 2;
			this.m_informationTP.Text = "Information";
			// 
			// m_informationRTB
			// 
			this.m_informationRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_informationRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_informationRTB.Location = new System.Drawing.Point(0, 0);
			this.m_informationRTB.Name = "m_informationRTB";
			this.m_informationRTB.Size = new System.Drawing.Size(728, 500);
			this.m_informationRTB.TabIndex = 0;
			this.m_informationRTB.Text = "";
			// 
			// m_graphRTB
			// 
			this.m_graphRTB.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_graphRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
			this.m_graphRTB.Location = new System.Drawing.Point(0, 0);
			this.m_graphRTB.Name = "m_graphRTB";
			this.m_graphRTB.Size = new System.Drawing.Size(728, 500);
			this.m_graphRTB.TabIndex = 0;
			this.m_graphRTB.Text = "";
			// 
			// GraphSingleView
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(736, 526);
			this.Controls.Add(this.m_tabControl);
			this.Name = "GraphSingleView";
			this.Text = "GraphView";
			this.m_tabControl.ResumeLayout(false);
			this.m_documentTP.ResumeLayout(false);
			this.m_graphTP.ResumeLayout(false);
			this.m_informationTP.ResumeLayout(false);
			this.ResumeLayout(false);

		}

		#endregion
	}
}